package com.z2k.jdbc.util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {

    public static Connection getConnection(){
        Properties pro = new Properties();
        InputStream in = null;
        Connection conn = null;
        String jdbcDriver = null;
        String jdbcUrl = null;
        String username = null;
        String password = null;
        in = DBUtil.class.getClassLoader().getResourceAsStream("db.properties");
        try {
            pro.load(in);
            jdbcDriver = pro.getProperty("driver");
            jdbcUrl = pro.getProperty("url");
            username = pro.getProperty("user");
            password = pro.getProperty("password");

            Class.forName(jdbcDriver);

            conn = DriverManager.getConnection(jdbcUrl,username,password);
            return conn;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
